#include "netrecv.h"
#include <QDebug>
#include <QThread>
#include "XUdp.h"

QMutex g_mutex_update;
bool g_IsRunningNet = false;
char g_recv_buf[1024*1024];

NetRecv::NetRecv(QObject *parent) : QObject(parent)
{

}

void NetRecv::ReadData()
{
    int recv_size;
    sockaddr_in client;
    while(g_IsRunningNet)
    {
        recv_size = 0;
        recv_size = g_pUdpclient->Recv(m_recv_data,sizeof (m_recv_data),&client);
        if(recv_size >=  0)
        {
            g_mutex_update.lock();
            memcpy(g_recv_buf,m_recv_data,recv_size);
            g_mutex_update.unlock();
            emit UpdateStatus(recv_size);
        }

        QThread::msleep(20);
    }


}


